﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using Model;
namespace DAL
{
   public class DAL_ConsumerBill
    {

        //根据餐桌ID和没有结账的状态查询账单信息 0表示未结账
       //餐桌消费情况
       public static DataTable XiaofeiQK(string TableID)
       {
           String sql = @" SELECT CBID,ProductName,CDPrice,CDAmount,CDDate,CDMoney from ConsumerDetail as c
join Products as p
on
c.ProdcutID=p.ProductID
where CBID IN(SELECT CBID FROM ConsumerBill
 WHERE TableID=@TableID AND CBClose=0)and CDType=0";
           List<SqlParameter> list = new List<SqlParameter>{
                new SqlParameter("@TableID",TableID)
           };
           return DBHelper.Dataset(sql, list);
       }

       //卓子的上桌次数次数
       public static object ShangZhuoS(string TableID)
       {
           String sql = @"  SELECT COUNT(*) FROM ConsumerBill
 WHERE TableID=@TableID";
           List<SqlParameter> list = new List<SqlParameter>{
                new SqlParameter("@TableID",TableID)
           };
           return DBHelper.Chadanzhi(sql, list.ToArray());
       }
       //所有卓子的上桌次数次数
       public static object SY_ShangZhuoS() {
           String sql = @"  SELECT COUNT(*) FROM ConsumerBill";
           return DBHelper.Chadanzhi(sql, null);
       }
       //添加消费账单
       public static int TJxf(Model_ConsumerBill m) {
           string sql = @"insert into ConsumerBill(CBID,TableID,CBAmount,VipID,
            CBDiscount,CBStartDate,AdminID,
            CBSale,CBClose) values(@CBID,@TableID,@CBAmount,@VipID,
@CBDiscount,GETDATE(),@AdminID,@CBSale,0)";
           List<SqlParameter> list = new List<SqlParameter>{
                new SqlParameter("@CBID",m.CBID),
                 new SqlParameter("@TableID",m.TableID),
                  new SqlParameter("@CBAmount",m.CBAmount),
                   new SqlParameter("@VipID",m.VipID),
                    new SqlParameter("@CBDiscount",m.CBDiscount),
                      new SqlParameter("@AdminID",m.AdminID),
                       new SqlParameter("@CBSale",m.CBSale),
           };
           return DBHelper.Update(sql, list.ToArray());
       
       }
       //获取正在消费的桌子单号
       public static SqlDataReader CXDH(string ID) {
           string sql = @"SELECT * FROM ConsumerBill
 WHERE  CBClose=0 AND TableID=@TableID";
           List<SqlParameter> list = new List<SqlParameter>{
                new SqlParameter("@TableID",ID)
           };
           return DBHelper.Zhilianshi(sql,list.ToArray());
       }
    }
}
